<?php

namespace App\Admin\Extensions;
use Dcat\Admin\Widgets\Modal;
use App\Admin\Controllers\UserController;
use App\Admin\Controllers\UserBingshiController;
use App\Admin\Controllers\UserDanganController;
use App\Admin\Controllers\UserWenjuanController;
use Dcat\Admin\Admin;
use Dcat\Admin\Widgets\Tab;

class AddDangan {
    public function __construct(){

    }
    public function render()
    {
        $url = admin_url('users');
        $modal = Modal::make()
        ->title('新增档案')
        ->body($this->view())
        ->xl()
        ->onShow(<<<JS
$('input[name=name]').parents('form').attr('action', '{$url}')
JS
        )
        ->button('<button class="btn btn-primary">新增档案</button>');
        return str_replace('modal-xl', 'modal-1000', $modal->render());
    }

    public function bingshiForm(){
        Admin::translation('user');
        return app()->make(UserBingshiController::class)->form(-1);
    }

    public function danganForm(){
        Admin::translation('user-dangan');
        return app()->make(UserDanganController::class)->form(-1);
    }
    public function wenjuanForm(){
        Admin::translation('user');
        return app()->make(UserWenjuanController::class)->form(-1);
    }

    public function view(){
        $tab = Tab::make();

        // 第一个参数是选项卡标题，第二个参数是内容，第三个参数是是否选中
        $tab->add('档案信息', $this->danganForm());
        $tab->add('病史信息', $this->bingshiForm());
        $tab->add('问卷信息', $this->wenjuanForm());

        return $tab->withCard();
    }
}